Skip to content

Refactor render API to auto-detect chart type from config#328

Merged
hustcc merged 5 commits intoaifrom
copilot/refactor-render-api-parameters
Feb 1, 2026
Merged

Refactor render API to auto-detect chart type from config#328
hustcc merged 5 commits intoaifrom
copilot/refactor-render-api-parameters

Conversation

Copy link
Contributor

Copilot AI commented Feb 1, 2026

The render() method required redundant type specification—passed both as first parameter and within syntax/config. This refactors to single-parameter API where type is auto-detected.

API Changes

Old:

g.render('pie', { data: [...] })
g.render('pie', 'vis pie\ndata\n...')

New:

g.render({ type: 'pie', data: [...] })
g.render('vis pie\ndata\n...')  // type extracted from syntax

Type detection logic:

  • Config objects: reads type field directly
  • Syntax strings: parses vis [type] declaration via existing parser
  • Throws clear error if type missing

Streaming simplified

Eliminates regex pattern matching:

// Before
const type = buffer.match(/vis\s+(\S+)/)?.[1];
if (type) gptVis.render(type, buffer);

// After
gptVis.render(buffer);  // type auto-detected

Other changes

  • Relocated parser: src/ai/parser.tssrc/syntax/parser.ts (better semantic organization)
  • Removed deprecated skills: .github/skills/gpt-vis-ai-*
  • Updated examples: All README, playground, and framework integration code updated

Breaking change

⚠️ Affects GPTVis class API only. Individual component APIs (Pie(), Bar(), etc.) unchanged.

Original prompt

帮我重构一下 render 这个 api。去掉第一个参数,直接传入 syntax string 或者 config object,在 render 函数中去判断 chart type。

注意:

  1. 所有组件的 render 函数都要改,都不需要第一个参数。
  2. 同步修改单元测试,各种组件 readme 文档,以及 playground 的代码
  3. 修改 readme,简化其中使用案例代码,无需再正则解析出 type 了。
  4. 保持代码代码简洁,最终根目录运行一下 npm run formar,解决 lint 问题

另外附带解决两个问题:

1.src/ai 下的 parser 代码,挪到 src/syntax 下面。
2. 删除 github 两个 skills,已经不需要了。


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@changeset-bot
Copy link

changeset-bot bot commented Feb 1, 2026

⚠️ No Changeset found

Latest commit: 36385b7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI changed the title [WIP] Refactor render API to simplify parameters and usage Refactor render API to auto-detect chart type from config Feb 1, 2026
Copilot AI requested a review from hustcc February 1, 2026 16:13
@hustcc hustcc marked this pull request as ready for review February 1, 2026 16:16
@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2026

😭 Deploy PR Preview 36385b7 failed. Build logs

🤖 By surge-preview

@hustcc hustcc merged commit 2b6adab into ai Feb 1, 2026
10 checks passed
@hustcc hustcc deleted the copilot/refactor-render-api-parameters branch February 1, 2026 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants